#!/bin/bash

# https://docs.docker.com/docker-cloud/builds/advanced/
# DockerHub starts this script in the /docker directory

set -e

echo DOCKERFILE_PATH="$DOCKERFILE_PATH"
echo DOCKER_REPO="$DOCKER_REPO"
echo IMAGE_NAME="$IMAGE_NAME"

if [[ "$DOCKER_REPO" = *"rlworkgroup/garage" ]]; then
  echo "Building target garage"
  docker build \
		-f "../$DOCKERFILE_PATH" \
		--build-arg BUILDKIT_INLINE_CACHE=1 \
		--target garage \
		-t "$IMAGE_NAME" \
		..
elif [[ "$DOCKER_REPO" = *"rlworkgroup/garage-nvidia" ]]; then
  echo "Building target garage-nvidia"
  docker build \
		-f "../$DOCKERFILE_PATH" \
		--build-arg BUILDKIT_INLINE_CACHE=1 \
		--target garage-nvidia \
		-t "$IMAGE_NAME" \
		--build-arg PARENT_IMAGE="nvidia/cuda:11.0-cudnn8-runtime-ubuntu18.04" \
		..
fi
